<template>
	<view class="overtime-list-wrapper">
		<view v-if="list.length" class="list-wrapper">
			<scroll-view scroll-y="true" class="scroll-Y" @scrolltolower="lower">
				<view class="list-wrapper-box" v-for="(item,index) in list" :key="index"  @click="goDetail(item.id,item.type)">
					<view class="list-wrapper-box-right">
						<view class="list-wrapper-box-right-title">
							<text class="list-wrapper-box-right-title-left">{{item.title}}</text>
							<text class="list-wrapper-box-right-title-right list-test">{{item.datetime||''}}</text>
						</view>
						<view class="list-test">申请人：：{{item.createUser}}</view>
						<view class="process refuse">{{item.stateText}}</view>
					</view>
				</view>
			</scroll-view>
		</view>
		<view v-else class="no-data-box">-- 暂无数据 --</view>
	</view>
</template>

<script>
	import api from '../../api.js';
	var util = require('../../common/util.js');
	export default {
		data() {
			return {
				page:1,
				type:'all',
				testName:'',
				userinfo: uni.getStorageSync('user'),	
				list: []
			};
		},
		onLoad(e) {		
			this.type=e.type||"all";
			this.testName=e.testName||'',
			this.getList();
		},
		onPullDownRefresh() {
			this.page=1;
			this.getList();
			setTimeout(function () {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		onReachBottom:function(){
		  this.page++;
		  this.getList();
		},
		methods: {
			getList() {
				var that=this
				api.post({
					url: 'api/testList.json',
					data: {
						page: this.page,
						type:this.type,
						testName:this.testName,
						userId:uni.getStorageSync('token'),
						limit: 10
					},
					success(result) {
						if(result.code==0){
							if(that.page==1)that.list=[];
							result.data.map((news) => {
								that.list.push({
									id: news.id,
									datetime: util.friendlyDate(news.createTime),
									title: news.testName,
									stateText:news.stateText,
									type:news.type,
									createUser:news.createUserName
								});
							});
							
						}else{
							this.loadingText='暂无数据';
						}
						
					}
				});
			},
			goDetail(id,type){
				uni.navigateTo({
					url: '/pages/jiance/detail'+type+'?id='+id
				})
			},
			lower(e) {
				console.log(e)
			}
		}
	}
</script>

<style lang="scss">
	
</style>
